|
|
|
|
|
|
|
The following kernel gives equal weight to all the pixels in a three-by-three area surrounding the center pixel. |
|
|
|
|
|
|
|
|
To apply this kernel to an area, the program multiplies the surrounding pixel values by their corresponding kernel entries and adds the results. The total gives the output value for the center pixel. |
|
|
|
|
|
|
|
|
The following example shows the input pixel values for a small part of an image. To compute the output value of the center pixel using the previous kernel, the program would multiply 1/9 * 6 + 1/9 * 2 + 1/9 * 9 + . . . + 1/9 * 2 = 5. |
|
|
|
|
|
|
|
|
More generally, suppose a program contains two picture boxes of the same size named picOriginal and picResult. The following code shows how the program might apply a three-by-three kernel with coefficients stored in the array kernel dimensioned symmetrically around zero. |
|
|
|
 |
|
|
|
|
' Apply a filter to an image. Private Sub ApplyFilter(kernel() As Single)
Dim bound As Integer
Dim input_pixels() As RGBTriplet
Dim result_pixels() As RGBTriplet
Dim bits_per_pixel As Integer
Dim X As Integer
Dim Y As Integer
Dim i As Integer
Dim j As Integer
Dim r As Integer
Dim g As Integer
Dim b As Integer
' Get the kernel's bounds. bound = UBound(kernel, 1)
' Get the pixels from picOriginal. GetBitmapPixels picOriginal, input_pixels, bits_per_pixel |
|
|
|
|
|